home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 5.7 KB | 187 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGrObj.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWGROBJ_H
- #define FWGROBJ_H
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTDDEF_H
- #include "FWStdDef.h"
- #endif
-
- #ifndef FWCLAINF_H
- #include "FWClaInf.h"
- #endif
-
- #ifndef FWAUTODE_H
- #include "FWAutoDe.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // Forward Declaration
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CGraphicCountedPtrRep;
- class FW_CLASS_ATTR FW_CGraphicCountedPtr;
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CGraphicCountedPtr &object);
- FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CGraphicCountedPtr &object);
-
- //========================================================================================
- // CLASS FW_CGraphicCountedPtr
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CGraphicCountedPtr FW_AUTO_DESTRUCT_OBJECT
- {
- friend FW_CReadableStream& operator>>(FW_CReadableStream&, FW_CGraphicCountedPtr&);
- friend FW_CWritableStream& operator<<(FW_CWritableStream&, const FW_CGraphicCountedPtr&);
-
- public:
- FW_DECLARE_CLASS
-
- public:
- FW_CGraphicCountedPtr();
- // Creates a "NULL" pointer.
-
- FW_CGraphicCountedPtr(const FW_CGraphicCountedPtr& other);
-
- virtual ~ FW_CGraphicCountedPtr();
- // Destroy the pointer.
- // Decrements the count in the rep, and deletes the rep if count is zero.
-
- FW_Boolean operator==(const FW_CGraphicCountedPtr& other) const;
- FW_Boolean operator!=(const FW_CGraphicCountedPtr& other) const;
-
- operator const void*() const;
- // Use to test if this is a "NULL" pointer.
-
- FW_Boolean IsSameRepAs(const FW_CGraphicCountedPtr& p) const;
-
- protected:
- void UpCount();
- // Implementation method, increment the reference count in rep.
-
- void DownCount();
- // Implementation method, decrement the reference count in rep.
- // Deletes rep if reference count is zero.
-
- FW_CGraphicCountedPtrRep* GetRep() const
- {return fRep;}
- void SetRep(FW_CGraphicCountedPtrRep* rep);
-
- private:
- FW_CGraphicCountedPtrRep *fRep;
- };
-
- //========================================================================================
- // class FW_CGraphicCountedPtrRep
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CGraphicCountedPtrRep
- {
- friend class FW_CLASS_ATTR FW_CGraphicCountedPtr;
-
- public:
- FW_DECLARE_CLASS
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
-
- public:
- FW_CGraphicCountedPtrRep();
- virtual ~FW_CGraphicCountedPtrRep();
-
- private:
- FW_CGraphicCountedPtrRep(const FW_CGraphicCountedPtrRep& otherRep);
- FW_CGraphicCountedPtrRep& operator=(const FW_CGraphicCountedPtrRep& otherRep) const;
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- unsigned long GetRefCount() const
- {return fRefCount;}
-
- virtual void Purge();
-
- virtual void Flatten(FW_CWritableStream& archive) const = 0;
-
- virtual FW_Boolean IsEqual(const FW_CGraphicCountedPtrRep* other) const = 0;
-
- static void Write(FW_CWritableStream& archive, const void* Rep);
-
- protected:
- void IncrementRefCount()
- {fRefCount++;}
- unsigned long Release()
- {return --fRefCount;}
-
- //----------------------------------------------------------------------------------------
- // Data Members
- //
- private:
- unsigned long fRefCount;
- };
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::operator==
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CGraphicCountedPtr::IsSameRepAs(const FW_CGraphicCountedPtr& p) const
- {
- return fRep == p.fRep;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::operator==
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CGraphicCountedPtr::operator==(const FW_CGraphicCountedPtr& other) const
- {
- return fRep->IsEqual(other.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::operator!=
- //----------------------------------------------------------------------------------------
- inline FW_Boolean FW_CGraphicCountedPtr::operator!=(const FW_CGraphicCountedPtr& other) const
- {
- return !fRep->IsEqual(other.fRep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicCountedPtr::operator const void*
- //----------------------------------------------------------------------------------------
- inline FW_CGraphicCountedPtr::operator const void*() const
- {
- return (const void*) fRep;
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-